﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufIParameterDisplayCustom.h"

namespace gcmp
{
    class IDocument;
    class IParameter;
}

namespace gnuf
{
    class Item;
    class CommonLineStyleButton;
    class CommonLineStyleButtonModel;
}

namespace gfam
{
    std::wstring GetFirstNumberString(std::wstring const & str);

    class LineStyleParameterDisplay : public gfam::IGnufParameterDisplayCustom
    {
    public:
        LineStyleParameterDisplay();

        //创建属性控件显示
        virtual gnuf::Item* OnDisplay(gnuf::NameValuePairBlock* pNameValuePairBlock, gcmp::IElement* pElement, int parameterId) override;
        virtual gnuf::Item* OnDisplay(gnuf::NameValuePairBlock* pNameValuePairBlock, const std::vector<gcmp::IElement*> & elements, int parameterId) override;

        void onClicked(gnuf::Item *);

        //获取当前属性控件值
        virtual gcmp::OwnerPtr<gcmp::IParameterValueStorage> GetValue(gcmp::IDocument* pDoc, const std::vector<gcmp::ElementId>& elements, const gnuf::Item* pItem) const override;

        static const std::wstring s_multiTypeText;

    private:
        //设置属性控件值
        void SetCurrentValueStorage(gcmp::OwnerPtr<gcmp::IParameterValueStorage> && currentValue)
        {
            m_currentValue = TransferOwnership(currentValue);
        }

        //设置关联图元对象
        gcmp::IElement * GetOwnerElement() const;
        void SetOwnerElements(const std::vector<gcmp::IElement*> &);

        gnuf::CommonLineStyleButton* GetLineStyleButton(gcmp::IElement * pElement, gnuf::NameValuePairBlock * pNameValuePairBlock, int parameterId);

        gcmp::OwnerPtr<gcmp::IParameter> GetParameter(gcmp::IElement * pElement, int parameterId);

        gcmp::OwnerPtr<gnuf::CommonLineStyleButtonModel> GetLineStyleModel(gcmp::IDocument* pDoc, gcmp::IParameter* opParam);

    private:
        gcmp::OwnerPtr<gcmp::IParameterValueStorage> m_currentValue;
        gnuf::CommonLineStyleButton* m_pCommonLineStyleButton;
        std::vector<gcmp::IElement*> m_elements;
        bool m_isLineType;
        bool m_isLineWidth;

        gcmp::OwnerPtr<gnuf::CommonLineStyleButtonModel> m_opLineStyleBtnModel;
    };
}
